<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="pessoa" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{pessoaHome.managed ? 'Edit' : 'Add'} Pessoa</f:facet>



            <s:decorate id="dataCadastroField" template="layout/edit.xhtml">
                <ui:define name="label">Data cadastro</ui:define>
                <h:inputText id="dataCadastro"
                          value="#{pessoaHome.instance.dataCadastro}">
                    <a:support event="onblur" reRender="dataCadastroField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="emailField" template="layout/edit.xhtml">
                <ui:define name="label">Email</ui:define>
                <h:inputTextarea id="email"
                               cols="80"
                               rows="3"
                           required="true"
                              value="#{pessoaHome.instance.email}"/>
            </s:decorate>


            <s:decorate id="nomeField" template="layout/edit.xhtml">
                <ui:define name="label">Nome</ui:define>
                <h:inputTextarea id="nome"
                               cols="80"
                               rows="3"
                              value="#{pessoaHome.instance.nome}"/>
            </s:decorate>



            <s:decorate id="senhaField" template="layout/edit.xhtml">
                <ui:define name="label">Senha</ui:define>
                <h:inputTextarea id="senha"
                               cols="80"
                               rows="3"
                              value="#{pessoaHome.instance.senha}"/>
            </s:decorate>


            <s:decorate id="statusField" template="layout/edit.xhtml">
                <ui:define name="label">Status</ui:define>
                <h:inputText id="status"
                          value="#{pessoaHome.instance.status}">
                    <a:support event="onblur" reRender="statusField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{pessoaHome.persist}"
                       disabled="#{!pessoaHome.wired}"
                       rendered="#{!pessoaHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{pessoaHome.update}"
                       rendered="#{pessoaHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{pessoaHome.remove}"
                      immediate="true"
                       rendered="#{pessoaHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Pessoa.xhtml"
                rendered="#{pessoaHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty pessoaFrom ? 'PessoaList' : pessoaFrom}.xhtml"
                rendered="#{!pessoaHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Questionario">
        <h:form styleClass="association" id="questionarioChildren">

            <h:outputText value="There are no questionario associated with this pessoa."
                       rendered="#{empty pessoaHome.questionario}"/>

            <rich:dataTable value="#{pessoaHome.questionario}"
                           var="_questionario"
                      rendered="#{not empty pessoaHome.questionario}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="questionarioTable">
                <rich:column sortBy="#{_questionario.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_questionario.id}"/>
                </rich:column>
                <rich:column sortBy="#{_questionario.cliques}">
                    <f:facet name="header">Cliques</f:facet>
                    <h:outputText value="#{_questionario.cliques}"/>
                </rich:column>
                <rich:column sortBy="#{_questionario.dataCadastro}">
                    <f:facet name="header">Data cadastro</f:facet>
                    <h:outputText value="#{_questionario.dataCadastro}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{pessoaHome.managed}" id="questionario">
        <div class="actionButtons">
            <s:button id="addquestionario"
                   value="Add questionario"
                    view="/QuestionarioEdit.xhtml"
             propagation="none">
                 <f:param name="pessoaId"
                         value="#{pessoaHome.instance.id}"/>
                 <f:param name="questionarioFrom" value="Pessoa"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
